﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace write
{
	public partial class Form2 : Form
	{
		public Form2()
		{
			this.InitializeComponent();
		}
		private void button1_Click(object sender, EventArgs e)
		{
			Form2.str_aa = this.textBox1.Text;
			base.DialogResult = DialogResult.OK;
		}

		// 
		private void button2_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		// 
		private void Form2_Load(object sender, EventArgs e)
		{
			this.textBox1.Text = Form2.str_aa;
			Form2.buf_a0 = Form1.getBYTE128(sender, this.textBox1);
			if ((int)Form2.buf_a0[0] > this.comboBox2.Items.Count)
			{
				this.comboBox2.SelectedText = Form2.buf_a0[1].ToString("X2");
			}
			else
			{
				this.comboBox2.SelectedIndex = (int)Form2.buf_a0[0];
			}
			if ((int)Form2.buf_a0[1] > this.comboBox1.Items.Count)
			{
				this.comboBox1.SelectedText = Form2.buf_a0[1].ToString("X2");
			}
			else
			{
				this.comboBox1.SelectedIndex = (int)Form2.buf_a0[1];
			}
			if ((int)Form2.buf_a0[2] > this.comboBox5.Items.Count)
			{
				this.comboBox5.SelectedText = Form2.buf_a0[1].ToString("X2");
			}
			else
			{
				this.comboBox5.SelectedIndex = (int)Form2.buf_a0[2];
			}
			byte b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox1.SetItemChecked(i, (Form2.buf_a0[3] & b) > 0);
				b = (byte)(b >> 1);
				Console.WriteLine("输出");
				Console.WriteLine((Form2.buf_a0[3] & b));
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox2.SetItemChecked(i, (Form2.buf_a0[4] & b) > 0);
				b = (byte)(b >> 1);
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox3.SetItemChecked(i, (Form2.buf_a0[5] & b) > 0);
				b = (byte)(b >> 1);
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox4.SetItemChecked(i, (Form2.buf_a0[6] & b) > 0);
				b = (byte)(b >> 1);
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox5.SetItemChecked(i, (Form2.buf_a0[7] & b) > 0);
				b = (byte)(b >> 1);
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox6.SetItemChecked(i, (Form2.buf_a0[8] & b) > 0);
				b = (byte)(b >> 1);
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox7.SetItemChecked(i, (Form2.buf_a0[9] & b) > 0);
				b = (byte)(b >> 1);
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox8.SetItemChecked(i, (Form2.buf_a0[10] & b) > 0);
				b = (byte)(b >> 1);
			}
			this.textBox2.Text = ((int)(Form2.buf_a0[12] * 100)).ToString();
			Console.WriteLine(Form2.buf_a0[0]);
			if ((int)Form2.buf_a0[13] > this.comboBox3.Items.Count)
			{
				this.comboBox3.SelectedText = Form2.buf_a0[13].ToString("X2");
			}
			else
			{
				this.comboBox3.SelectedIndex = (int)Form2.buf_a0[13];
			}
			this.textBox3.Text = Form2.buf_a0[14].ToString();
			this.textBox5.Text = ((int)(Form2.buf_a0[15] * 100)).ToString();
			this.textBox6.Text = ((int)(Form2.buf_a0[16] * 10)).ToString();
			this.textBox4.Text = ((int)(Form2.buf_a0[17] * 10)).ToString();
			this.textBox7.Text = ((int)(Form2.buf_a0[18] * 10)).ToString();
			this.textBox8.Text = ((int)(Form2.buf_a0[19] * 10)).ToString();
			string text = "";
			for (int i = 37; i < 40; i++)
			{
				text += Form2.buf_a0[i].ToString("X02");
			}
			this.textBox9.Text = text;
			text = "";
			for (int i = 56; i < 60; i++)
			{
				string str = text;
				char c = (char)Form2.buf_a0[i];
				text = str + c.ToString();
			}
			this.textBox10.Text = text;
			text = ((int)Form2.buf_a0[60] * 256 + (int)Form2.buf_a0[61]).ToString() + "." + Form2.buf_a0[62].ToString("D2");
			this.textBox11.Text = text;
			text = Form2.buf_a0[66].ToString();
			this.textBox13.Text = text + "%";
			this.textBox12.Text = Form2.buf_a0[67].ToString() + "%";
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox9.SetItemChecked(i, (Form2.buf_a0[92] & b) > 0);
				b = (byte)(b >> 1);
			}
			b = 128;
			for (int i = 0; i < 8; i++)
			{
				this.checkedListBox10.SetItemChecked(i, (Form2.buf_a0[93] & b) > 0);
				b = (byte)(b >> 1);
			}
			if ((int)Form2.buf_a0[94] > this.comboBox4.Items.Count)
			{
				this.comboBox4.SelectedText = Form2.buf_a0[94].ToString("X2");
				return;
			}
			this.comboBox4.SelectedIndex = (int)Form2.buf_a0[94];
		}

		// 
		private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
		{
			Form2.buf_a0[0] = (byte)this.comboBox2.SelectedIndex;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		//
		private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			Form2.buf_a0[1] = (byte)this.comboBox1.SelectedIndex;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
		{
			Form2.buf_a0[13] = (byte)this.comboBox3.SelectedIndex;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
		{
			Form2.buf_a0[94] = (byte)this.comboBox4.SelectedIndex;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox1.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			
			Form2.buf_a0[3] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox2_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox2.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[4] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox3_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox3.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[5] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox4_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox4.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[6] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox5_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox5.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[7] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox6_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox6.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[8] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox7_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox7.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[9] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox8_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox8.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[10] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox9_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox9.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[92] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void checkedListBox10_SelectedIndexChanged(object sender, EventArgs e)
		{
			byte b = 0;
			byte b2 = 128;
			for (int i = 0; i < 8; i++)
			{
				if (this.checkedListBox10.GetItemChecked(i))
				{
					b |= b2;
				}
				b2 = (byte)(b2 >> 1);
			}
			Form2.buf_a0[93] = b;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void button3_Click(object sender, EventArgs e)
		{
			int num = Convert.ToInt32(this.textBox3.Text);
			Form2.buf_a0[14] = (byte)num;
			num = Convert.ToInt32(this.textBox5.Text);
			Form2.buf_a0[15] = (byte)(num / 100);
			num = Convert.ToInt32(this.textBox6.Text);
			Form2.buf_a0[16] = (byte)(num / 10);
			num = Convert.ToInt32(this.textBox4.Text);
			Form2.buf_a0[17] = (byte)(num / 10);
			num = Convert.ToInt32(this.textBox7.Text);
			Form2.buf_a0[18] = (byte)(num / 10);
			num = Convert.ToInt32(this.textBox8.Text);
			Form2.buf_a0[19] = (byte)(num / 10);
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void textBox3_TextChanged(object sender, EventArgs e)
		{
			int num = Convert.ToInt32(this.textBox3.Text);
			if (num >= 25)
			{
				this.textBox5.Text = "25500";
				this.textBox5.ForeColor = Color.Red;
				return;
			}
			this.textBox5.Text = (num * 1000).ToString();
		}

		// 
		private void textBox5_TextChanged(object sender, EventArgs e)
		{
			if (Convert.ToInt32(this.textBox5.Text) >= 25500)
			{
				this.textBox5.Text = "25500";
				this.textBox5.ForeColor = Color.Red;
				return;
			}
			this.textBox5.ForeColor = Color.Black;
		}

		// 
		private void button4_Click(object sender, EventArgs e)
		{
			string text = this.textBox9.Text.Trim();
			while (text.Length < 6)
			{
				text += "0";
			}
			for (int i = 0; i < 3; i++)
			{
				Form2.buf_a0[37 + i] = Convert.ToByte(text.Substring(i * 2, 2), 16);
			}
			string text2 = "";
			for (int i = 0; i < 128; i++)
			{
				text2 = text2 + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text2 += "\r\n";
				}
			}
			this.textBox1.Text = text2;
		}

		// 
		private void button5_Click(object sender, EventArgs e)
		{
			string text = this.textBox10.Text.Trim();
			while (text.Length < 3)
			{
				text += " ";
			}
			for (int i = 0; i < 3; i++)
			{
				Form2.buf_a0[56 + i] = (byte)Convert.ToChar(text.Substring(i, 1));
			}
			string text2 = "";
			for (int i = 0; i < 128; i++)
			{
				text2 = text2 + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text2 += "\r\n";
				}
			}
			this.textBox1.Text = text2;
		}

		// 
		private void button6_Click(object sender, EventArgs e)
		{
			int num = (int)((Convert.ToDouble(this.textBox11.Text.Trim()) + 1E-07) * 100.0);
			Form2.buf_a0[62] = (byte)(num % 100);
			num /= 100;
			Form2.buf_a0[60] = (byte)(num / 256);
			Form2.buf_a0[61] = (byte)(num % 256);
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
		{
			Form2.buf_a0[2] = (byte)this.comboBox5.SelectedIndex;
			string text = "";
			for (int i = 0; i < 128; i++)
			{
				text = text + Form2.buf_a0[i].ToString("X02") + " ";
				if ((i + 1) % 16 == 0)
				{
					text += "\r\n";
				}
			}
			this.textBox1.Text = text;
		}

		// 
		public static string str_aa = "";

		// 
		public static byte[] buf_a0 = new byte[128];
	}
}
